package com.结构型模式.代理模式;

import javax.swing.*;
import java.awt.*;

/**
 * 特产
 */
interface Specialty{
    void display();
}

/**
 * 婺源特产
 */
class WySpecilty extends JFrame implements Specialty{
    WySpecilty(){
        super("韶关代理婺源特产");
        this.setLayout(new GridLayout(1,2));
        JLabel l1 = new JLabel(new ImageIcon("src/img/WuyuanSpecialty.jpg"));
        this.add(l1);
        this.pack();
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    @Override
    public void display() {
        System.out.println("老子这 有花生，美女");
        this.setVisible(true);
    }
}

/**
 *韶关代理
 */
class SgProxy implements Specialty{
    private Specialty wySpecilty  = new WySpecilty();
    @Override
    public void display() {
        preRequest();
        wySpecilty.display();
        postRequest();
    }

    /**
     * 请求前处理
     */
    void preRequest(){
        System.out.println("此山是我开，" +
                "" +
                "此树是我摘，" +
                "要想从这过，" +
                "留下买路财");
    }

    /**
     * 请求后处理
     */
    void postRequest(){
        System.out.println("客观慢走，下来再来啊");
    }
}
/**
 * 代理模式
 */
public class ProxyPattern {
    public static void main(String[] args) {
        SgProxy sgProxy = new SgProxy();
        sgProxy.display();
    }
}
